//index.js
//获取应用实例
var app = getApp()
var fileData = require('../../utils/data.js')

Page({
  // 页面初始数据
  data: {
      loading: true,
      hasMore: true,
      navTopItems: fileData.getRouteNavData(),  //导航
      navSectionItems: fileData.getRouteNavSectionData(), //导航数据
      curNavId: 1,  // 当前导航项ID
		  curIndex: 0 //当前导航索引，数组从0开始
  },
  // 监听页面加载
  onLoad:function(){
    this.curid = 0
    var that = this
    that.setData({
      list: that.data.navSectionItems
    })
  },
  //导航切换
  switchTab: function(e) {
      let id = e.target.dataset.id,
      index = parseInt(e.target.dataset.index)
      this.curid = parseInt(e.target.dataset.index)
      this.setData({
        curNavId: id,
        curIndex: index
      })
  },
  // 跳转至详情页
  navigateDetail: function(e){
    wx.navigateTo({
      url:'../detail/detail?artype=' + e.currentTarget.dataset.artype
    })
  },
  // 加载更多数据
  loadMore: function (e) {
    
    var curid = this.curid
    var tip_curid = 'tip_' + this.curid
    this.setData({
      tip_curid:tip_curid
    })

    if (this.data.navSectionItems[curid].length === 0) return
    
    var that = this
    //that.setData({ loading: true })

    that.data.navSectionItems[curid] = that.data.navSectionItems[curid].concat(that.data.navSectionItems[curid])
    that.setData({
      // loading: false,
      list: that.data.navSectionItems,
      tip_curid:''
    })
      
  }
  
})
